$(function () {
    initLast();
    $('#delete').click(function () {
        $('#search_r').val('')
    });
    $('#searchBtn').click(function () {
        var search = $('#search_r').val();
        if (search) {
            searchStorages(search);
        }
        location.href = 'pro_list.html?search=' + search;
    });
    $('#myText,#last').delegate('dd', 'click', function () {
        location.href = 'pro_list.html?search=' + $(this).text();
    });
    $('#del').tap(function () {
        var _vm = $(this);
        _vm.siblings('dd').remove()
    });

    function initLast() {
        var lastSearchs = LsyStorage.getItem('lastSearchs');
        lastSearchs = lastSearchs ? lastSearchs : [];
        var str = '<dt>最近搜索</dt><dt class="del" id="del"></dt>';
        for (var i = 0, n = lastSearchs.length; i < n; i++) {
            str += '<dd>' + lastSearchs[i] + '</dd>';
        }
        $('#last').html(str);
    }

    function searchStorages(search) {
        var lastSearchs = LsyStorage.getItem('lastSearchs');
        lastSearchs = lastSearchs ? lastSearchs : [];
        if (lastSearchs.length >= 10) {
            lastSearchs.shift();
        }
        lastSearchs.push(search);
        LsyStorage.setItem('lastSearchs', lastSearchs);
    }

});